#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
void write(int x)
{
    if(x<0)
        putchar('-'),x=-x;
    if(x>9)
        write(x/10);
    putchar('0'+x%10);
}
const int N=2e5+5,M=2e6+5;
int cur[N],n,a[N],las[N];
void solve()
{
    n=read();
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
    }
    int mx=0;
    for(int i=0;i<(1<<n);i++)
    {
        for(int j=1;j<=n;j++)
            cur[j]=(i>>(j-1))&1;
        int ans=0;
        for(int j=2;j<=n;j++)
        {
            for(int k=j-1;k;k--)
            {
                if(cur[j]==cur[k])
                {
                    if(a[j]==a[k])
                        ans+=a[j];
                    break;
                }
            }
        }
        mx=max(mx,ans);
    }
    write(mx);
    puts("");
}
signed main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int dd=read();
    while(dd--)
        solve();
    return 0;
}
